module Sparkle
  module Helper

    def render_sparkle options
      key = rand(2**128).to_s(36)
      Rails.cache.write(key, options)
      if options[:locals].values.any? { |value| value._sparkle_cached_ if value.class.include?(Refreshable) }
        options[:locals][:sparkle_cache_key] = key
      else
        options[:locals][:sparkle_cache_key] = nil
      end
      render options
    end

  end
end

